package com.wangrui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wangrui.dto.AllClassGrade;
import com.wangrui.pojo.ClassGrade;
import com.wangrui.mapper.ClassGradeMapper;
import com.wangrui.pojo.Major;
import com.wangrui.service.ClassGradeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangrui.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王锐
 * @since 2020-07-10
 */
@Service
public class ClassGradeServiceImpl extends ServiceImpl<ClassGradeMapper, ClassGrade> implements ClassGradeService {
    @Autowired
    private ClassGradeMapper classGradeMapper;
    @Override
    public Map<String, Object> AllClassGrades(Page<AllClassGrade> page1) {
        List<AllClassGrade> allClassGrade = classGradeMapper.getAllClassGrade(page1);
        HashMap<String, Object> map = new HashMap<>();
        map.put("rows",allClassGrade);
        map.put("total",classGradeMapper.selectCount(null));
        return map;
    }

    @Override
    public int classGradeSave(ClassGrade classGrade) {
        return classGradeMapper.insert(classGrade);
    }

    @Override
    public int classGradeUpdate(ClassGrade classGrade) {
        return classGradeMapper.updateById(classGrade);
    }

    @Override
    public int classGradeDelete(int ids) {
        return classGradeMapper.deleteById(ids);
    }

    @Override
    public List<ClassGrade> queryMajorsJson() {
            QueryWrapper<ClassGrade> queryWrapper = new QueryWrapper<>();
            queryWrapper.select("id","class_name");
            return classGradeMapper.selectList(queryWrapper);
    }
}
